#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>

void reverse(char* p1, char* p2)
{
	while (p1 < p2)
	{
		char temp = *p1;
		*p1 = *p2;
		*p2 = temp;
		p1++;
		p2--;
	}
}

void leftround1(char arr[], int k)
{
	int len = strlen(arr);
	int time = k % len;
	for (int i = 0;i < time;i++)
	{
		int j = 0;
		char temp = arr[0];
		for (;j < len - 1;j++)
		{
			arr[j] = arr[j + 1];
		}
		arr[j] = temp;
	}
}

void leftround2(char arr[], int k)
{
	int len = strlen(arr);
	int time = k % len;
	char arr1[256] = { 0 };
	strcpy(arr1, arr + time);
	strncat(arr1, arr, time);
	strcpy(arr, arr1);
}

void leftround3(char arr[], int k)
{
	int len = strlen(arr);
	int time = k % len;
	reverse(arr, arr + time - 1);
	reverse(arr + time, arr + len - 1);
	reverse(arr, arr + len - 1);
}

int main()
{
	char arr[] = "abbcde";
	int k = 0;
	printf("请输入左旋k值：>");
	scanf("%d", &k);
	//leftround1(arr, k);
	//leftround2(arr, k);
	leftround3(arr, k);
	printf("%s", arr);
}